﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        int ticknumber = 0;
        int topicnumber = 0;
        int firstnum;
        int secnum;
        int _operator;//1表示加，2表示减
        int result;
        int correct=0;
        int wrong=0;
        Random r = new Random();


        public Form1()
        {
            InitializeComponent();
            timer1.Enabled = true;
            generate();
        }
        public void generate()
        {
            firstnum = r.Next(1,101);
            secnum = r.Next(1,101);
            _operator = r.Next(1, 3);
            if (_operator == 1)
            {
                result = firstnum + secnum;
                label2.Text = Convert.ToString(firstnum) + "+" + Convert.ToString(secnum);
            }
            else if(_operator==2)
            {
                result = firstnum - secnum;
                label2.Text = Convert.ToString(firstnum) + "-" + Convert.ToString(secnum);
            }
            topicnumber++;
            
        }

        private void btn_Confirm_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(textBox1.Text) == result)
            {
                correct++;
                label5.Text = Convert.ToString(correct);
            }
            else
            {
                wrong++;
                label7.Text = Convert.ToString(wrong);
            }
            textBox1.Text = null;
            ticknumber = 0;
            if (topicnumber >= 10)
            {
                timer1.Enabled = false;

                MessageBox.Show("答题完成，共答对"+Convert.ToString(correct)+"道题目;共答错"+Convert.ToString(wrong)+"道题目");
            }
            else
            {
                generate();
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label9.Text = Convert.ToString(ticknumber);
            ticknumber++;
            if (ticknumber == 20)
            {
                MessageBox.Show("您已超时，自动跳转到下一题");
                wrong++;
                label7.Text = Convert.ToString(wrong);
                
                ticknumber = 0;
                generate();
            }

        }
    }
}
